package com.adapters;

import java.util.ArrayList;

import com.witejavi.eneagrama.R;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.TextView;

public class MiAdapterListaPeliculas extends ArrayAdapter<String>{

	private ArrayList<String> lista;
	private ArrayList<Integer> fondos;
	private Context context;
    	
    public MiAdapterListaPeliculas(Activity activity, Context context, ArrayList<String> listaTitulos, ArrayList<Integer> listaFondos) {
    	super(context, R.layout.hijo_peliculas, listaTitulos);
    	
		this.context = context;		
		this.lista = listaTitulos;
		this.fondos = listaFondos;
        
	}   

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {		
		
		View view = null;
        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(context);
            
            view = inflater.inflate(R.layout.hijo_peliculas, null);
            TextView eneatipo = (TextView) view.findViewById(R.id.TextViewEneatipo);
            TextView numero = (TextView) view.findViewById(R.id.textViewNumero);
            FrameLayout fondo = (FrameLayout) view.findViewById(R.id.FrameLayoutFondoNumero);
            
            eneatipo.setText(lista.get(position));
            numero.setText(Integer.toString(position+1));
            fondo.setBackgroundResource(fondos.get(position));
        } else {
            view = convertView;
        }
 		
        return view;
	}
	
	@Override
	public int getViewTypeCount() {  
		if (getCount() < 1)
			return 1;
	    return getCount();
	}

	@Override
	public int getItemViewType(int position) {
	    return position;
	}
	
	@Override
	public int getCount() {

		return lista.size();
	}

	@Override
	public long getItemId(int pos) {
		return pos;
	}
	
	
}
